package zuo.from0516.other.day02;

public class Code03_DoubleEndsQueueToStackAndQueue {
    public static class Node<T>{
        public T value;
        public Node<T> last;
        public Node<T> next;

        public Node(T value) {
            this.value = value;
        }
    }

    public static class DoubleEndsQueue<T>{
        public Node<T> head;
        public Node<T> tail;

        /**
         * 从头部加节点
         * @param value
         */
        public void addFromHead(T value){
            Node<T> cur=new Node<T>(value);
            if (head==null){
                head=cur;
                tail=cur;
            }else{
                cur.next=head;
                head.last=cur;
                head=cur;
            }
        }

        /**
         * 从尾部加节点
         * @param value
         */
        public void addFromBottom(T value){
            Node<T> cur=new Node<>(value);
            if (head==null){
                head=cur;
                tail=cur;
            }else{
                cur.last=tail;
                tail.next=cur;
                tail=cur;
            }
        }

    }


}
